package com.lwd1513.designPattern.factory.absfactory;


/**
 * @Author: 刘东（挂兰）
 * @Date: 2023/11/17 00:06:32
 * @Description: 抽象工厂个人理解
 * 扩展点
 * 奶茶点 推行套餐 xx奶茶 ++ 冰激凌
 */
public class MilkTeaStore {
    public static void main(String[] args) {
        MilkTeaStore milkTeaStore = new MilkTeaStore();
        milkTeaStore.order(new PackageA());
        milkTeaStore.order(new PackageB());
        /**
         * 优点 有新套餐组合不需要修改代码(if) 只要新增新的奶茶类和奶茶类对于的抽象工厂就好了
         */
    }
    /**
     *
     * @param abstractFactory 入参是抽象工厂的实现类
     *                        抽象工厂产生2种产品 可以随意组合套餐
     */
    public void order(AbstractFactory abstractFactory) {
        // 获取不同口味的奶茶奶茶
        MilkTea milkTea = abstractFactory.productMilkTea();
        Icecream icecream = abstractFactory.productIcecream();
        System.out.println(String.format("你的套餐有%s+%s", milkTea.getName(), icecream.getName()));
    }
}

/**
 * 套餐A 西瓜奶茶+巧克力冰激凌
 */
class PackageA extends AbstractFactory{

    @Override
    public MilkTea productMilkTea() {
        return new WaterMelonMilkTea();
    }

    @Override
    public Icecream productIcecream() {
        return new ChocolateIcecream();
    }
}

/**
 * 套餐B 草莓奶茶+奶油草莓冰激凌
 */
class PackageB extends AbstractFactory {

    @Override
    public MilkTea productMilkTea() {
        return new StrawberryMilkTea();
    }

    @Override
    public Icecream productIcecream() {
        return new StrawberryIcecream();
    }
}

abstract class AbstractFactory {
    /**
     * 产生奶茶
     */
    public abstract MilkTea productMilkTea();

    /**
     * 产生冰激凌
     */
    public abstract Icecream productIcecream();
}

/**
 * 奶茶类-基类
 */
abstract class MilkTea {
    public abstract String getName();
    public void addIce() {
        System.out.println("加冰...");
    }
    public void addSugar() {
        System.out.println("加糖...");
    }
    public void addHot() {
        System.out.println("加热...");
    }
}

abstract class Icecream {
    public abstract String getName();

    public void addContainer() {
        System.out.println("加甜筒");
    }
    public void addIce() {
        System.out.println("加" + getName());
    }
}

/**
 * 草莓为奶茶
 */
class StrawberryMilkTea extends MilkTea {
    @Override
    public String getName() {
        return "草莓奶茶";
    }
}
/**
 * 西瓜味奶茶
 */
class WaterMelonMilkTea extends MilkTea {
    @Override
    public String getName() {
        return "西瓜奶茶";
    }
}

/**
 * 巧克力甜筒
 */
class ChocolateIcecream extends Icecream {
    @Override
    public String getName() {
        return "巧克力";
    }
}

/**
 * 草莓奶油甜筒
 */
class StrawberryIcecream extends Icecream {
    @Override
    public String getName() {
        return "草莓奶油";
    }
}